home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap2 / 2_7 / testhost.pl < prev    next >
Encoding:
Perl Script  |  1996-06-15  |  692 b   |  40 lines

  1. #!/usr/bin/perl
  2.  
  3. # Send the output mime type to the server to know what output to handle.
  4.  
  5. print "Content-type: text/html\n\n";
  6.  
  7. # Print HTML header information.
  8.  
  9. print <<EOH;
  10. <HTML>
  11. <HEAD><TITLE>CGI Script How-to: Test Script</TITLE></HEAD>
  12. <BODY>
  13. <H1>CGI Script How-to<BR>determine the client machine's name</H1>
  14. EOH
  15.  
  16. # Access the environment variable by name
  17.  
  18. if ($ENV{'REMOTE_HOST'})
  19. {
  20.     $remote_host = $ENV{'REMOTE_HOST'};
  21. }
  22. elsif ($ENV{'REMOTE_ADDR'})
  23. {
  24.     $remote_host = $ENV{'REMOTE_ADDR'};
  25. }
  26. else
  27. {
  28.     $remote_host = "somewhere on the Internet";
  29. }
  30.  
  31. print "Hello, you are a user from <B>$remote_host</B>\n";
  32.  
  33. # Print closing HTML tags.
  34.  
  35. print "</BODY></HTML>\n";
  36.  
  37. #
  38. # end of testhost.pl
  39. #
  40.